#!/usr/bin/env node

/**
 * 同步安装程序 package.json 版本与主 package.json
 * 由 semantic-release 使用以保持版本同步
 */

const fs = require('fs');
const path = require('path');

function syncInstallerVersion() {
  // Read main package.json
  const mainPackagePath = path.join(__dirname, '..', 'package.json');
  const mainPackage = JSON.parse(fs.readFileSync(mainPackagePath, 'utf8'));
  
  // Read installer package.json
  const installerPackagePath = path.join(__dirname, 'installer', 'package.json');
  const installerPackage = JSON.parse(fs.readFileSync(installerPackagePath, 'utf8'));
  
  // 更新安装程序版本以匹配主版本
  installerPackage.version = mainPackage.version;
  
  // 写回安装程序 package.json
  fs.writeFileSync(installerPackagePath, JSON.stringify(installerPackage, null, 2) + '\n');
  
  console.log(`已同步安装程序版本至 ${mainPackage.version}`);
}

// Run if called directly
if (require.main === module) {
  syncInstallerVersion();
}

module.exports = { syncInstallerVersion };